home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Image / GIS / Renderer / GD.php next >
PHP Script  |  2004-03-24  |  3KB  |  115 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: GD Renderer                                    |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: GD.php,v 1.4 2004/01/01 10:31:39 sebastian Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/Renderer.php';
  20.  
  21. /**
  22. * GD Renderer.
  23. *
  24. * @version  $Revision: 1.4 $
  25. * @since    Image_GIS 1.0.0
  26. */
  27. class Image_GIS_Renderer_GD extends Image_GIS_Renderer {
  28.     /**
  29.     * GD Image Palette.
  30.     *
  31.     * @var array $palette
  32.     */
  33.     var $palette = array();
  34.  
  35.     /**
  36.     * GD Image Ressource.
  37.     *
  38.     * @var ressource $img
  39.     */
  40.     var $img;
  41.  
  42.     /**
  43.     * Constructor.
  44.     *
  45.     * @param  mixed   $width
  46.     * @param  integer $sizyY
  47.     * @param  boolean $debug
  48.     * @access public
  49.     */
  50.     function Image_GIS_Renderer_GD($width, $height, $debug) {
  51.         if (is_file($width)) {
  52.             $this->img = imagecreatefrompng($width);
  53.             $width     = imagesx($this->img);
  54.             $height    = imagesy($this->img);
  55.  
  56.             $this->Image_GIS_Renderer($width, $height, $debug);
  57.         } else {
  58.             $this->Image_GIS_Renderer($width, $height, $debug);
  59.  
  60.             $this->img = imagecreate($this->width, $this->height);
  61.             imagecolorallocate($this->img, 255, 255, 255);
  62.         }
  63.     }
  64.  
  65.     /**
  66.     * Draws a line from ($x1, $y1) to ($x2, $y2)
  67.     * using the color rgb($r, $g, $b).
  68.     *
  69.     * @param  float   $x1
  70.     * @param  float   $y1
  71.     * @param  float   $x2
  72.     * @param  float   $y2
  73.     * @param  float   $r
  74.     * @param  float   $g
  75.     * @param  float   $b
  76.     * @access public
  77.     */
  78.     function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) {
  79.         if (!isset($this->palette[$r][$g][$b])) {
  80.             $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b);
  81.         }
  82.  
  83.         imageline(
  84.           $this->img,
  85.           $x1,
  86.           $y1,
  87.           $x2,
  88.           $y2,
  89.           $this->palette[$r][$g][$b]
  90.         );
  91.     }
  92.  
  93.     /**
  94.     * Saves the rendered image to a given file.
  95.     *
  96.     * @param  string  $filename
  97.     * @return boolean
  98.     * @access public
  99.     */
  100.     function saveImage($filename) {
  101.         return imagepng($this->img, $filename);
  102.     }
  103.  
  104.     /**
  105.     * Shows the rendered image.
  106.     *
  107.     * @access public
  108.     */
  109.     function showImage() {
  110.         header('Content-Type: image/png');
  111.         imagepng($this->img);
  112.     }
  113. }
  114. ?>
  115.